<script setup lang="ts">
const selected = ref(1)

const select = (num: number) => {
  selected.value = num
}
</script>

<template>
  <div class="space-y-10">
    <div class="antialiased bg-gray-200 p-8">
      <div class="flex justify-center">
        <nav class="w-56 relative">
          <!-- 该 span 元素就是动画的背景，通过设置 transform 属性来实现动画效果 -->
          <span
              class="absolute h-10 w-full bg-white rounded-lg shadow-md ease-out transition-transform transition-duration-200"
              :style="{ transform: `translateY(calc(100% * ${selected}))` }"
          ></span>
          <ul class="relative">
            <li v-for="(item, index) in 4" :key="index">
              <button
                  type="button"
                  @click="select(index)"
                  :aria-selected="selected === index"
                  class="py-2 px-3 w-full flex items-center focus:outline-none focus-visible:underline"
              >
                <svg
                    :class="selected === index ? 'text-indigo-400' : 'text-gray-500'"
                    class="h-6 w-6 transition-all ease-out transition-duration-200"
                    viewBox="0 0 24 24"
                    fill="currentColor"
                >
                  <path
                      fill-rule="evenodd"
                      clip-rule="evenodd"
                      d="M12.707 2.293a1 1 0 00-1.414 0l-9 9a1 1 0 101.414 1.414L4 12.414V21a1 1 0 001 1h5a1 1 0 001-1v-6h2v6a1 1 0 001 1h5a1 1 0 001-1v-8.586l.293.293a1 1 0 001.414-1.414l-9-9zM18 10.414l-6-6-6 6V20h3v-6a1 1 0 011-1h4a1 1 0 011 1v6h3v-9.586z"
                  />
                </svg>
                <span
                    :class="selected === index ? 'text-indigo-600' : 'text-gray-700'"
                    class="ml-2 text-sm font-medium transition-all ease-out transition-duration-200"
                >
                Home
              </span>
              </button>
            </li>
          </ul>
        </nav>
      </div>
    </div>

    <div class="antialiased bg-gray-200 p-8">
      <div class="flex justify-center">
        <nav class="w-56 relative">
          <!-- 该 span 元素就是动画的背景，通过设置 transform 属性来实现动画效果 -->
          <span
              class="absolute h-10 w-25 bg-white rounded-lg shadow-md ease-out transition-transform transition-duration-200"
              :style="{ transform: `translateX(calc(100% * ${selected}))` }"
          ></span>
          <ul class="relative flex">
            <li v-for="(item, index) in 4" :key="index">
              <button
                  type="button"
                  @click="select(index)"
                  :aria-selected="selected === index"
                  class="py-2 px-3 w-full flex items-center focus:outline-none focus-visible:underline"
              >
                <svg
                    :class="selected === index ? 'text-indigo-400' : 'text-gray-500'"
                    class="h-6 w-6 transition-all ease-out transition-duration-200"
                    viewBox="0 0 24 24"
                    fill="currentColor"
                >
                  <path
                      fill-rule="evenodd"
                      clip-rule="evenodd"
                      d="M12.707 2.293a1 1 0 00-1.414 0l-9 9a1 1 0 101.414 1.414L4 12.414V21a1 1 0 001 1h5a1 1 0 001-1v-6h2v6a1 1 0 001 1h5a1 1 0 001-1v-8.586l.293.293a1 1 0 001.414-1.414l-9-9zM18 10.414l-6-6-6 6V20h3v-6a1 1 0 011-1h4a1 1 0 011 1v6h3v-9.586z"
                  />
                </svg>
                <span
                    :class="selected === index ? 'text-indigo-600' : 'text-gray-700'"
                    class="ml-2 text-sm font-medium transition-all ease-out transition-duration-200"
                >
                Home
              </span>
              </button>
            </li>
          </ul>
        </nav>
      </div>
    </div>
  </div>

</template>

<style scoped lang="scss">

</style>